import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'node:path';

const isProd = process.env.NODE_ENV === 'production';

export default defineConfig({
  plugins: [vue()],
  server: {
    host: '0.0.0.0',
    port: 7500,
    proxy: {
      '/admin-api': {
        target: 'http://localhost:7501',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/admin-api/, '/api'),
      },
    },
  },
  build: {
    outDir: 'dist',
    minify: isProd,
    sourcemap: isProd ? false : 'inline',
    rollupOptions: {
      output: {
        chunkFileNames: 'assets/js/[name]-[hash].js', //代码块文件名
        entryFileNames: 'assets/js/[name]-[hash].js', //入口文件名
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 资源文件名
      },
    },
  },
  base: isProd ? '/mobile/' : '/',
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
});
